Skip to content

Reset blocking::SimpleClient::pos before every read#265

Merged
MathiasKoch merged 1 commit into
FactbirdHQ:masterfrom
Rimpampa:fix-client
Jul 13, 2026
Merged

Reset blocking::SimpleClient::pos before every read#265
MathiasKoch merged 1 commit into
FactbirdHQ:masterfrom
Rimpampa:fix-client

Conversation

@Rimpampa

Copy link
Copy Markdown
Contributor

No description provided.

let until = Instant::now() + self.config.tx_timeout;
let mut pos = 0;
while pos < self.pos {
while pos < len {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This loop does not seem right? While the change is correct (len instead of self.pos), the self.buf bound and the pos increment seems wrong?

I think it would be better to use self.rw.write_all(&self.buf[..len]) instead of hand-rolling it, unless you have a particular reason for hand-rolling the same?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right about that, I don't know how I missed that 😅.

The hand-rolling is necessary tho, write_ready signals that the next write will be block-free, but write_all may perform as many writes as it needs.
If we cannot add any check in-between write calls the timeout won't work and the client may get stuck indefinitely depending on the inner writer.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair, in that case pos += self.rw.write(&self.buf[pos..len]).or(Err(Error::Write))?;

@MathiasKoch MathiasKoch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍

@MathiasKoch
MathiasKoch merged commit 125330d into FactbirdHQ:master Jul 13, 2026
8 checks passed
@Rimpampa
Rimpampa deleted the fix-client branch July 13, 2026 12:46
JcBernack pushed a commit to rocknitive/atat that referenced this pull request Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants